//
//  UIButton+Category.m
//  OralRobot
//
//  Created by 王桂敏 on 16/4/1.
//  Copyright © 2016年 huayingdai. All rights reserved.
//

#import "UIButton+Category.h"


@implementation UIButton (Category)

+ (UIButton *)buttonOfHorizontal1ForNormalWithImage:(NSString *)imageName
                                             title:(NSString *)title
                                             frame:(CGRect)frame
                                            target:(id)target
                                            action:(SEL)action
                                        titleColor:(UIColor *)titleColor
                                    backgroudColor:(UIColor *)backgroudColor
                                              font:(UIFont *)font{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    button.frame = frame;
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    
    [button setImage:Image(imageName) forState:UIControlStateNormal];
    button.titleEdgeInsets = UIEdgeInsetsMake(0, w(5), 0, 0);
    
    button.titleLabel.font = font;
    button.backgroundColor = backgroudColor;
    
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    
    return button;
    
}

+ (UIButton *)buttonOfHorizontalForNormalWithImage:(NSString *)imageName
                                            title:(NSString *)title
                                            frame:(CGRect)frame
                                           target:(id)target
                                           action:(SEL)action
                                       titleColor:(UIColor *)titleColor
                                   backgroudColor:(UIColor *)backgroudColor
                                             font:(UIFont *)font{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    button.frame = frame;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    button.titleLabel.font = font;
    button.backgroundColor = backgroudColor;
    
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *rightbuton = [UIButton buttonOfImageForNormalWithImage:imageName frame:CGRectMake(button.width - w(100), 0, w(100), button.height) target:target action:action];
    rightbuton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [rightbuton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    rightbuton.imageView.x = button.width - rightbuton.imageView.width - w(10);
    rightbuton.imageView.userInteractionEnabled = YES;
    [button addSubview:rightbuton.imageView];
    
    return button;

}

+ (UIButton *)buttonOfVerticalOForNormalWithImage:(NSString *)imageName
                                            title:(NSString *)title
                                            frame:(CGRect)frame
                                           target:(id)target
                                           action:(SEL)action
                                       titleColor:(UIColor *)titleColor
                                   backgroudColor:(UIColor *)backgroudColor
                                             font:(UIFont *)font{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    button.frame = frame;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = backgroudColor;
    
    UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    imageButton.frame = CGRectMake(0, 0, getW(button), getH(button) / 4 * 3);
    [imageButton setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAutomatic] forState:UIControlStateNormal];
    imageButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [imageButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [button addSubview:imageButton];
    
    
    
    UILabel *label = [UILabel labelWithTitle:title frame:CGRectMake(0, getH(button) / 3 * 2, getW(button), getH(button) / 3) font:font textColor:titleColor bgColor:[UIColor clearColor]];
    label.textAlignment = NSTextAlignmentCenter;
    [button addSubview:label];
    
    return button;
    
}

+ (UIButton *)buttonOfImageForNormalWithImage:(NSString *)imageName
                                        frame:(CGRect)frame
                                       target:(id)target
                                       action:(SEL)action{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return button;
    
}
+ (UIButton *)buttonOfTitleForNormalWithTitle:(NSString *)title
                                        frame:(CGRect)frame
                                       target:(id)target
                                       action:(SEL)action
                                   titleColor:(UIColor *)titleColor
                               backgroudColor:(UIColor *)backgroudColor
                                         font:(UIFont *)font{

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;
    [button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = backgroudColor;
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    button.titleLabel.font = font;

    return button;
}


@end
